//
//  ContactPageViewController.m
//  Zyachting
//
//  Created by NGUYEN THE HUNG on 10/30/12.
//
//

#import "ContactPageViewController.h"
#import "ImageViewerController.h"
#import "AppDelegate.h"
@interface ContactPageViewController ()

@end

@implementation ContactPageViewController
@synthesize lblFax,lblTel1,lblTel2,lblMail1,lblMail2,lblMail3,lblSkype,lblMobile,lblMSM,tvDescription,index;
@synthesize lblTitle;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupView];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)setupView
{
    ImageViewerController* imageViewer = [[ImageViewerController alloc] initWithNibName:@"ImageViewerController" bundle:nil];
    [imageViewer setIsLocal:YES];
    if (index == 1) {
        //First
        self.tvDescription.text = @"Urb. Lomas de Campoamor\
        Avenida de Ibiza 16 Bl. I nr 1-2\
        03189 Orihuela Costa (Alicante)\
        España (Roadmap)";
        self.lblTel1.text   =   @"+34 966 775 048";
        self.lblMobile.text =   @"+34 603 447 459";
        self.lblFax.text    =   @"+34 966 775 048";
        self.lblMail1.text  =   @"info@golf-estates.com";
        self.lblMail2.text  =   @"nordic@golf-estates.com";
        self.lblMail3.text  =   @"rusia@golf-estates.com";
        self.lblTel2.text   =   @"+32 495 644 051";
        self.lblSkype.text  =   @"Golf-Estates";
        self.lblMSM.text    =   @"info@golf-estates.com";
        self.lblTitle.text  =   @"Z-Yachting barcos y Apartamentos S.L.";
        NSArray* arr = [NSArray arrayWithObjects:@"office-outside.jpeg",@"office-inside.jpeg", nil];
        [imageViewer setImageList:arr];

    }else{
        self.tvDescription.text = @"Avenida La Mancha\
        Altos de la Bahia F9 Manz 14 n°210\
        03183 Torrevieja (Alicante)\
        España (Roadmap) )";
        self.lblTel1.text   =   @"+34 966 925 328";
        self.lblMobile.text =   @"+34 630 764 350";
        self.lblFax.text    =   @"+34 966 925 328";
        self.lblMail1.text  =   @"info@z-yachting.com";
        self.lblMail2.text  =   @"nordic@z-yachting.com";
        self.lblMail3.text  =   @"rusia@z-yachting.com";
        self.lblTel2.text   =   @"+32 495 644 051";
        self.lblSkype.text  =   @"Z-Yachting";
        self.lblMSM.text    =   @"info@z-yachting.com";
        self.lblTitle.text  =   @"Golf-estates Costa Blanca S.L.";
        NSArray* arr = [NSArray arrayWithObjects:@"zy-office-outside.jpeg",@"zy-office-inside.jpeg", nil];
        [imageViewer setImageList:arr];
    }
    self.imageViewerController = [imageViewer autorelease];
    [self.view addSubview:self.imageViewerController.view];
}
-(IBAction)sendUsMessage:(id)sender
{
    MFMailComposeViewController* mailComposer = [[MFMailComposeViewController alloc] init];
    [mailComposer setMailComposeDelegate:self];
    [mailComposer setToRecipients:@[@"info@z-yachting.com"]];
    [[self appDelegate].tabBarController presentViewController:mailComposer animated:YES completion:NULL];
    [mailComposer release];
}
-(IBAction)urlTapped:(id)sender
{
    if ([sender tag] == 0) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.z-yachting.com"]];
    }else{
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.golf-estates.com"]];
    }
}
-(IBAction)btnTapped:(id)sender
{
    switch ([sender tag]) {
        case 0:
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.lblTel1.text]]];
        }
            break;
        case 1:
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.lblMobile.text]]];
        }
            break;
        case 6:
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.lblTel2.text]]];
        }
            break;
        case 3:
        case 4:
        case 5:
        {
            MFMailComposeViewController* mailComposer = [[MFMailComposeViewController alloc] init];
            switch ([sender tag]) {
                case 3:
                    [mailComposer setToRecipients:[NSArray arrayWithObjects:self.lblMail1.text, nil]];
                    break;
                case 4:
                    [mailComposer setToRecipients:[NSArray arrayWithObjects:self.lblMail2.text, nil]];
                    break;
                case 5:
                    [mailComposer setToRecipients:[NSArray arrayWithObjects:self.lblMail3.text, nil]];
                    break;
                default:
                    break;
            }

            [mailComposer setMailComposeDelegate:self];
            [[self appDelegate].tabBarController presentViewController:mailComposer animated:YES completion:NULL];
            [mailComposer release];
        }
            break;
        default:
            break;
    }
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [[self appDelegate].tabBarController dismissViewControllerAnimated:YES completion:NULL];
    
}
-(AppDelegate*)appDelegate
{
    return (AppDelegate*)([UIApplication sharedApplication].delegate);
}
@end
